package com.lixinyu.mp.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lixinyu.mp.entity.User;
import com.lixinyu.mp.mapper.UserMapper;
import com.lixinyu.mp.service.IUserService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService{
    @Autowired
    private UserMapper userMapper;

    @Override
    public IPage<User> getPage(int currentPage, int pageSize) {
        IPage<User> userPage = new Page<>(currentPage, pageSize);
        userMapper.selectPage(userPage,null);
        return userPage;
    }

    @Override
    public IPage<User> getPage(int currentPage, int pageSize, User user) {
        LambdaQueryWrapper<User> userLambdaQueryWrapper = new LambdaQueryWrapper<>();
        userLambdaQueryWrapper.like(Strings.isNotEmpty(user.getUserName()),User::getUserName,user.getUserName());
        userLambdaQueryWrapper.like(Strings.isNotEmpty(user.getPassword()),User::getPassword,user.getPassword());
        IPage<User> userPage = new Page<>(currentPage, pageSize);
        userMapper.selectPage(userPage,userLambdaQueryWrapper);
        return userPage;
    }
}
